package API.DAY11.reflect;

import API.DAY11.reflect.annotation.AutoRunClass;
import API.DAY11.reflect.annotation.AutoRunMethod;

import java.lang.reflect.Method;
import java.util.Scanner;

public class Test4 {
    public static void main(String[] args) throws Exception{
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入类名:");
        String className = scanner.nextLine();
        Class cls = Class.forName(className);

        if (cls.isAnnotationPresent(AutoRunClass.class)) {
            Object obj = cls.newInstance();
            Method[] methods = cls.getMethods();
            for (Method method:methods){
                if(method.isAnnotationPresent(AutoRunMethod.class)){
                    System.out.println("实例化");
    //                Object obj = cls.newInstance();
    //                System.out.println(obj);
                    method.invoke(obj);
                }
            }
        } else {
            System.out.println("该类没有被标注");
        }
    }
}
